package cn.wolfcode.crm.web.controller;


import cn.wolfcode.crm.domain.Applyer;
import cn.wolfcode.crm.query.ApplyerQueryObject;
import cn.wolfcode.crm.service.IApplyerService;
import cn.wolfcode.crm.util.JSONResult;
import cn.wolfcode.crm.util.PageResult;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("applyer")
public class ApplyController {

    @Autowired
    private IApplyerService applyerService;

    @RequestMapping("view")
    public String view(){
        return "apply/apply";
    }

    @ResponseBody
    @RequestMapping("query")
    public PageResult query(ApplyerQueryObject qo) {
        return applyerService.query(qo);
    }

    @RequestMapping("delete")
    @RequiresPermissions(value = {"applyer:delete","应聘消息删除"},logical = Logical.OR)
    @ResponseBody
    public JSONResult delete(Long id) {
        try {
            applyerService.deleteByPrimaryKey(id);
            return JSONResult.success("");
        } catch (Exception e) {
            e.printStackTrace();
            return JSONResult.mark("删除失败");
        }
    }

    @ResponseBody
    @RequestMapping("saveOrUpdate")
    @RequiresPermissions(value = {"applyer:saveOrUpdate","应聘消息新增或编辑"},logical = Logical.OR)
    public JSONResult saveOrUpdate(Applyer applyer){
        try {
            if(applyer.getId() != null){
                applyerService.updateByPrimaryKey(applyer);
            }else{
                applyerService.insert(applyer);
            }
            return JSONResult.success("");
        } catch (Exception e) {
            e.printStackTrace();
            return JSONResult.mark("操作失败");
        }
    }
}
